import {
    Mesh, MeshStandardMaterial, SphereGeometry, Line,
    PointsMaterial,
    Points,
    CylinderGeometry,
    MeshBasicMaterial, BoxBufferGeometry, LineLoop, Object3D, Plane,
    PlaneGeometry,
    TextureLoader, BufferGeometry, Material, Color, Group, Sprite, SpriteMaterial
} from 'three'
import { VertexNormalsHelper } from 'three/examples/jsm/helpers/VertexNormalsHelper';
import {
    picTexture,
    wallDisplay,
    wallRoughness,
    wallMap,
    dmDisplayTexture,
    dmMapTexture,
    dmRoughnessTexture,
    woodDisplayTexture,
    woodMapTexture,
    woodRoughnessTexture,
    picInfoTexture,
} from './loader'

/*
//物体
const meshArr: Object3D[] = []
const cycleMesh: Line = new Line(
    //几何
    new SphereGeometry(15, 32, 16),
    //材质
    new MeshStandardMaterial({color: 'rgb(0,0,255)'})
)

cycleMesh.position.x = 15


const lineLoop = new LineLoop(
    new SphereGeometry(15,32,16),
    new MeshStandardMaterial({color: 'rgb(100,200,255)'})
)
lineLoop.position.z = 20

const zhuziPoint:Points = new Points(
    new CylinderGeometry(10,20,30,32,5),
    new PointsMaterial({color: 'rgb(100,200,0)'})
)

zhuziPoint.position.x = -25
*/


//添加材料
const rect: Mesh = new Mesh(
    new BoxBufferGeometry(20,20,20),
    new MeshStandardMaterial({
        color: 'rgb(255, 255,255)',
        roughness: 0,
        // metalness: 1.0, //设置金属感, 金属使用1.0
    })
)
//移动rect物体的位置
rect.position.y = 10;
rect.position.x = 30;
//开启 投影
rect.castShadow = true;

//给rect添加法线 辅助线
const vertexNormalsHelper: VertexNormalsHelper = new VertexNormalsHelper(rect, 10, 0x0000ff);
//法线辅助线跟随rect物体移动
vertexNormalsHelper.position.x = 20;


//添加地面
const dm: Mesh = new Mesh<BoxBufferGeometry, MeshStandardMaterial>(
    new BoxBufferGeometry(500,10,300),
    new MeshStandardMaterial({
        color: 'rgb(200,200,200)',
        roughness: 0, //设置粗糙度,0为镜面,1为粗糙
        roughnessMap: dmRoughnessTexture,
        map: dmMapTexture,
        bumpMap: dmDisplayTexture
    })
)
dm.position.y = -5;
//开启 地板接收阴影
dm.receiveShadow = true;
// dm.castShadow = true;


// console.log('地面-矩阵', dm.matrixWorld, dm.matrix)

//添加墙面
export const wall: Mesh = new Mesh<BufferGeometry, Material>(
    new BoxBufferGeometry(500,300,10),
    new MeshStandardMaterial({
        color: '#fff',
        // roughness: 1,
        // roughnessMap: wallRoughness,
        // bumpMap: wallDisplay,
        // map: wallMap

    })
)
wall.position.set(0, 150, -100)

//手动触发 wall物体的矩阵数据计算, 先计算matrix, 在更新 matrixWorld
wall.updateMatrix()
wall.updateMatrixWorld()


/*wall.addEventListener('mouseenter', e =>{
    console.log('wall-mouseenter')
})
wall.addEventListener('mouseleave', e =>{
    console.log('wall-mouseleave')
})*/

//将相框, 照片, 介绍 放入 组
const group: Group = new Group();

//添加相框
const picFrame = new Mesh(
    new BoxBufferGeometry(100,80, 10,5),
    new MeshStandardMaterial({
        roughnessMap: woodRoughnessTexture,
        bumpMap: woodDisplayTexture,
        map: woodMapTexture
    })
)

// picFrame.position.z = -6

//添加照片
const picture: Mesh = new Mesh(
    new PlaneGeometry(80,60, 5,5),
    new MeshStandardMaterial({
        color: '#fff',
        map: picTexture, //颜色贴图
    })
)
// picture.position.y = 100
picture.position.z = 6


/*
//添加照片信息
const pictureInfo: Mesh = new Mesh<BufferGeometry, Material | Material[]>(
    new PlaneGeometry(32,18,),
    new MeshBasicMaterial({
        map: picInfoTexture
    })
)
// 需求: 该信息, 始终面对着镜头, 让信息可以被看到
// 每次渲染前, 将物体焦距对着相机的位置
pictureInfo.onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
    pictureInfo.lookAt(camera.position)
}*/

//添加照片信息: 使用精灵 实现, 对着镜头
const pictureInfo: Sprite = new Sprite(
    new SpriteMaterial({
        map: picInfoTexture,
        depthTest: false, //不启用深度(层级)测试, 即层级在最上层
        depthWrite: false,
        // sizeAttenuation: false,
    })
)
pictureInfo.scale.set(32,18,1)

pictureInfo.position.y = 50

group.add(picFrame)
group.add(picture)
group.add(pictureInfo)
group.position.y = 250
group.position.z = -90



export default [
    // rect,
    // vertexNormalsHelper,
    dm,
    wall,
    // picFrame,
    // picture,
    group,
]

/**
 * MeshBasicMaterial 该材质不受光照影像
 *
 */